<template>
	<view>
		<view class="smart-page-head">
			<view class="smart-page-head-litle">button按钮</view>
		</view>
		<view>
			<view class="uni-padding-warp uni-common-mt">
				<form @submit="formSubit" @reset="formReset">
					<view class="uni-form-item uni-column">
						<view class="title">姓名</view>
						<input class="uni-input" name="nickname" placeholder="请输入姓名" />
					</view>
					<view class="uni-form-item uni-column">
						<view class="title">性别</view>
						<radio-group name="gender">
							<lable>
								<radio value="男" /><text>男</text>
							</lable>
							<lable>
								<radio value="女" /><text>女</text>
							</lable>
						</radio-group>
					</view>
					<view class="uni-form-item uni-column">
						<view class="title">爱好</view>
						<radio-group name="gender">
							<lable>
								<radio value="读书" /><text>读书</text>
							</lable>
							<lable>
								<radio value="写字" /><text>写字</text>
							</lable>
						</radio-group>
					</view>
					<view class="uni-form-item uni-column">
						<view class="title">年龄</view>
						<slider value="20" name="age" show-value=""></slider>
					</view>
					<view class="uni-form-item uni-column">
						<view class="title">保留选项</view>
						<view>
							<switch name="switch"></switch>
						</view>
					</view>
				</form>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				
			}
		},
		methods: {
			formSubmit: function(e){
				console.log('form发生了submit事件，携带数据为：'+ JSON.stringify(e.detail.value));
				var rule=[
					{name:"nickname",checkType:"string",checkRule:"1,3",errorMsg:"姓名应为1~3个字符"},
					{name:"gender",checkType:"int",checkRule:"男,女",errorMsg:"请选择性别"},
					{name:"loves",checkType:"notnull",checkRule:"",errorMsg:"请选择爱好"},
				];
				var formData = e.datatil.value;
				var checkRes = graceChecker.check(formData,rule);
				if(checkRes){
					uni.showToast({
						title:"验证通过！",
						icon:"none",
						});
				}else{
					uni.showToast({
						title:graceChecker.error,
						icon:"none"
					});
				}
			},
			formReset:function(e){
				console.log('清空数据')
			}
		}
	}
</script>

<style>
	.uni-form-item .title {
		padding: 20rpx 0;
	}
</style>